import store from '@/store'

export default {
	install(Vue) {
		Vue.prototype.$utils = {
			// 全局方法
			checkPermission(value) {
				//ZCZY-18027 首页增加菜单判断
				const permissionLists = store.getters['log/permissionLists'] || [];
				const primaryMenusList = store.getters['log/primaryMenusList'] || [];
				const roles = permissionLists.concat(primaryMenusList)
				if (value && value instanceof Array) {
					if (value.length > 0) {
						const permissionRoles = value

						const hasPermission = roles.some(role => {
							return permissionRoles.includes(role)
						})
						return hasPermission
					}
				} else {
					throw new Error(`need roles! Like v-permission="['admin','editor']"`)
				}
			}
		}
	}
}
